package com.example.ffepeg.ffe;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class TaskTEst {

    //修改图片的尺寸
    public static void main(String[] args) {
        String url = "C:\\Users\\Administrator\\Desktop\\outImp4.jpg";
        String out = "src/main/resources/file/logo/outPng.jpg";
        boolean b = updateImgSize(url, out);
    }


    public static boolean updateImgSize(String inputImagePath, String outputImagePath){
        try {
            int targetWidth = 1440;
            int targetHeight = 960;
            // 读取原始图像
            File inputFile = new File(inputImagePath);
            BufferedImage inputImage = ImageIO.read(inputFile);
            // 创建目标尺寸的空白图像
            BufferedImage outputImage = new BufferedImage(targetWidth, targetHeight, inputImage.getType());

            // 获取图像绘制对象并设置抗锯齿
            Graphics2D g2d = outputImage.createGraphics();
            g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
            g2d.drawImage(inputImage, 0, 0, targetWidth, targetHeight, null);
            g2d.dispose();

            // 输出调整后的图像
            File outputFile = new File(outputImagePath);
            ImageIO.write(outputImage, "jpg", outputFile);
            return true;
        } catch (IOException e) {
           throw new RuntimeException("Error: " + e.getMessage());
        }
    }
}
